home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / misc / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.7 KB  |  108 lines

  1. package sun.misc;
  2.  
  3. public class Timer {
  4.    public Timeable owner;
  5.    long interval;
  6.    long sleepUntil;
  7.    long remainingTime;
  8.    boolean regular;
  9.    boolean stopped;
  10.    Timer next;
  11.    static TimerThread timerThread = null;
  12.  
  13.    public Timer(Timeable var1, long var2) {
  14.       this.owner = var1;
  15.       this.interval = var2;
  16.       this.remainingTime = var2;
  17.       this.regular = true;
  18.       this.sleepUntil = System.currentTimeMillis();
  19.       this.stopped = true;
  20.       synchronized(this.getClass()) {
  21.          if (timerThread == null) {
  22.             timerThread = new TimerThread();
  23.          }
  24.  
  25.       }
  26.    }
  27.  
  28.    public synchronized boolean isStopped() {
  29.       return this.stopped;
  30.    }
  31.  
  32.    public void stop() {
  33.       long var1 = System.currentTimeMillis();
  34.       synchronized(timerThread) {
  35.          synchronized(this) {
  36.             if (!this.stopped) {
  37.                TimerThread.dequeue(this);
  38.                this.remainingTime = Math.max(0L, this.sleepUntil - var1);
  39.                this.sleepUntil = var1;
  40.                this.stopped = true;
  41.             }
  42.          }
  43.  
  44.       }
  45.    }
  46.  
  47.    public void cont() {
  48.       synchronized(timerThread) {
  49.          synchronized(this) {
  50.             if (this.stopped) {
  51.                this.sleepUntil = Math.max(this.sleepUntil + 1L, System.currentTimeMillis() + this.remainingTime);
  52.                TimerThread.enqueue(this);
  53.                this.stopped = false;
  54.             }
  55.          }
  56.  
  57.       }
  58.    }
  59.  
  60.    public void reset() {
  61.       synchronized(timerThread) {
  62.          synchronized(this) {
  63.             this.setRemainingTime(this.interval);
  64.          }
  65.  
  66.       }
  67.    }
  68.  
  69.    public synchronized long getStopTime() {
  70.       return this.sleepUntil;
  71.    }
  72.  
  73.    public synchronized long getInterval() {
  74.       return this.interval;
  75.    }
  76.  
  77.    public synchronized void setInterval(long var1) {
  78.       this.interval = var1;
  79.    }
  80.  
  81.    public synchronized long getRemainingTime() {
  82.       return this.remainingTime;
  83.    }
  84.  
  85.    public void setRemainingTime(long var1) {
  86.       synchronized(timerThread) {
  87.          synchronized(this) {
  88.             if (this.stopped) {
  89.                this.remainingTime = var1;
  90.             } else {
  91.                this.stop();
  92.                this.remainingTime = var1;
  93.                this.cont();
  94.             }
  95.          }
  96.  
  97.       }
  98.    }
  99.  
  100.    public synchronized void setRegular(boolean var1) {
  101.       this.regular = var1;
  102.    }
  103.  
  104.    protected Thread getTimerThread() {
  105.       return TimerThread.timerThread;
  106.    }
  107. }
  108.